//
//  GraphCapsule.swift
//  SwiftUi
//
//  Created by xm on 30/08/2025.
//

import SwiftUI
import UIKit





struct GraphCapsule: View {
    
    var index: Int
    var height: Double
    var range: Range<Double>
    var overallRange: Range<Double>
    @State private var isExpanded = false

    var heightRatio: Double {
        max(magnitude(of: range) / magnitude(of: overallRange), 0.15)
    }
    var offsetRetio: Double {
        (range.lowerBound - overallRange.lowerBound) / magnitude(of: overallRange)
    }
    var animation: Animation {
          Animation.spring(dampingFraction: 0.5)
              .speed(2)
               .delay(0.03 * Double(index))
      }
    
    var body: some View {
        Capsule()
            .fill(.white)
            .frame(height: height * heightRatio, alignment: .bottom)
            .offset(x:0, y: height * -offsetRetio)
            .animation(animation)
    }
}

#Preview {
    GraphCapsule(index: 0, height: 150, range: 10..<50, overallRange: 0..<100)
}
